package br.unicamp.ic.sgct.server.dominio.entidades;

//import it.biobytes.ammentos.AutomaticType;
//import it.biobytes.ammentos.PersistentEntity;
//import it.biobytes.ammentos.PersistentField;
//import it.biobytes.ammentos.PersistentList;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.TableGenerator;

import br.unicamp.ic.sgct.client.dominio.to.CentroConvencaoTO;
import br.unicamp.ic.sgct.client.dominio.to.SalaTO;
import br.unicamp.ic.sgct.client.dominio.to.StandTO;

//@SuppressWarnings("serial")
//@PersistentEntity(sourceDomain = "T_CENTROCONV", primaryKey = "id_cconv")
@Entity
@Table(name="T_CENTROCONV")
@TableGenerator(name = "CENTROCONVENCAO_GEN", allocationSize = 1, initialValue = 1, table = "T_ID", 
		pkColumnName = "key", valueColumnName = "valor", pkColumnValue = "ID_CCONV")
public class CentroConvencao implements Serializable {
		//@PersistentField(fieldName="id_cconv", automatic=true, automaticType=AutomaticType.FRAMEWORK)
		@Id
		@Column(name="id_cconv")
		@GeneratedValue(strategy = GenerationType.TABLE, generator = "CENTROCONVENCAO_GEN")
		private long id;

		//@PersistentField(size="25")
		@Column(length=25)
		private String nome;

		//@PersistentField(size="18")
		@Column(length=18)
		private String fone;

		//@PersistentField(size="18")
		@Column(length=18)
		private String fax;

		//@PersistentField(size="50")
		@Column(length=50)
		private String endereco;
		
		//@PersistentList(query = "id_cconv=?", cascadeOnSave = true, cascadeOnDelete = false, deleteOnRemove = false)
		@OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY, mappedBy = "centroConvencao")
		private List<Stand> stands;
		
		//@PersistentList(query = "id_cconv=?", cascadeOnSave = true, cascadeOnDelete = false, deleteOnRemove = false)
		@OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY, mappedBy = "centroConvencao")
		private List<Sala> salas;

		public CentroConvencao() {
			super();
		}

		/**
		 * 
		 * @param nome
		 * @param fone
		 * @param fax
		 * @param endereco
		 */
		public CentroConvencao(String nome, String fone, String fax,
				String endereco) {
			super();
			this.nome = nome;
			this.fone = fone;
			this.fax = fax;
			this.endereco = endereco;
		}

		//~ getters & setters
		public long getId() {
			return id;
		}

		public void setId(long id) {
			this.id = id;
		}

		public String getNome() {
			return nome;
		}

		public void setNome(String nome) {
			this.nome = nome;
		}

		public String getFone() {
			return fone;
		}

		public void setFone(String fone) {
			this.fone = fone;
		}

		public String getFax() {
			return fax;
		}

		public void setFax(String fax) {
			this.fax = fax;
		}

		public String getEndereco() {
			return endereco;
		}

		public void setEndereco(String endereco) {
			this.endereco = endereco;
		}

		public List<Stand> getStands() {
			return stands;
		}

		public void setStands(List<Stand> stands) {
			this.stands = stands;
		}

		public List<Sala> getSalas() {
			return salas;
		}

		public void setSalas(List<Sala> salas) {
			this.salas = salas;
		}

		/**
		 * Constructs a <code>String</code> with all attributes
		 * in name = value format.
		 *
		 * @return a <code>String</code> representation 
		 * of this object.
		 */
		public String toString()
		{
		    final String TAB = "    ";

		    String retValue = "";

		    retValue = "CentroConvencao ( "
		        + super.toString() + TAB
		        + "id = " + this.id + TAB
		        + "nome = " + this.nome + TAB
		        + "fone = " + this.fone + TAB
		        + "fax = " + this.fax + TAB
		        + "endereco = " + this.endereco + TAB
		        + "stands = " + (this.stands != null ? this.stands.toString() + TAB : "NULL ")
		        + "salas = "  + (this.salas  != null ? this.salas.toString()  + TAB : "NULL ")
		        + " )";

		    return retValue;
		}
		
		
		
		public CentroConvencaoTO getTo(){
			CentroConvencaoTO centroTo = new CentroConvencaoTO();
			centroTo.setEndereco( this.getEndereco() );
			centroTo.setFax( this.getFax() );
			centroTo.setFone( this.getFone() );
			centroTo.setId( this.getId() );
			centroTo.setNome( this.getNome() );
			centroTo.setSalas(new ArrayList<SalaTO>());
			centroTo.setStands(new ArrayList<StandTO>());
			for (Sala sala : salas) {
				centroTo.getSalas().add(sala.getTo());	
			}
			for (Stand stand: stands) {
				centroTo.getStands().add(stand.getTo());
			}
			return centroTo;
		}
}